package com.ysx.ch02;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CalAspect {

    private static final int MAX=10;
    private static final String MESSAGE_SUCCESS ="我会算";
    private static final String MESSAGE_FAILURE ="我不会算";

    @Before(value = "execution(int com.ysx.ch02.Cal.add(int,int)) && args(x,y)")
    private boolean check(int x, int y){
        System.out.println("check..");
        return x<MAX && y<MAX;
    }

    @AfterReturning(value = "execution(int com.ysx.ch02.Cal.add(int,int))")
    private void printSuccess(){
        System.out.println(MESSAGE_SUCCESS);
    }
    private void printFailure(){
        System.out.println(MESSAGE_FAILURE);
    }

    private void print8(int rs,int x, int y){
        if(rs ==8){
            System.out.println("x="+x+" y="+y);
        }
    }

}
